<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivityUsers extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $sql = <<<SQL
        create table dx_activity_users
        (
            id int unsigned not null auto_increment
                primary key,
            wechat_uid int unsigned not null,
            invite_uid int unsigned default null comment '邀请的用户id',
            popularity int unsigned default 0 comment '人缘卡',
            tacit int unsigned default 0 comment '默契值',
            used_popularity int unsigned default 0 comment '已经使用的人缘卡数量',
            used_tacit int unsigned default 0 comment '已经使用的默契值数量',
            total_popularity int unsigned default 0 comment '总共获取到的人缘卡数量',
            total_tacit int unsigned default 0 comment '总共获取到的默契值数量',
            invite int unsigned default 0 comment '邀请的用户数量',
            answer_goods_id int unsigned default null comment '选择的商品',
            create_time timestamp null default null,
            update_time timestamp default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
        )comment '活动参与用户';
SQL;
        if (!DB::statement($sql)) {
            throw new \Exception("failed on execute SQL: [{$sql}]");
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        throw new \Exception('downgrade is forbidden');
    }
}
